#include "StdAfx.h"
#include "ConsumerCarModel.h"


ConsumerCarModel::ConsumerCarModel(void)
{
	m_id = -1;
	m_consumerID = -1;
	m_carType = -1;
	m_carBrand = -1;
	m_buyTime = -1;
	m_buyPrice = _T("");
	m_appraisement = _T("");
	m_propertyRight = -1;
	m_installmentTm = -1;
	m_installmentSum = _T("");
	m_installmentBank = "";
	m_monthPay = _T("");
	m_cutPaymentCard = -1;
}

ConsumerCarModel::~ConsumerCarModel(void)
{
}

void ConsumerCarModel::parseFromJson(Json::Value& jsonData)
{
	if (!jsonData["buyCarType"].isNull()) 
	{
		this->m_carType = jsonData["buyCarType"].asInt();
	}
	if (!jsonData["carBrand"].isNull()) 
	{
		this->m_carBrand = jsonData["carBrand"].asInt();
	}
	if (!jsonData["buyTime"].isNull()) 
	{
		this->m_buyTime = jsonData["buyTime"].asInt();
	}
	CUtils::getJsonStringField(jsonData, "buyPrice", m_buyPrice);
	CUtils::getJsonStringField(jsonData, "appraisePrice", m_appraisement);
	CUtils::getJsonStringField(jsonData, "loanMoney", m_installmentSum);
	CUtils::getJsonStringField(jsonData, "monthPay", m_monthPay);
	
	if (!jsonData["propertyRight"].isNull()) 
	{
		this->m_propertyRight = jsonData["propertyRight"].asInt();
	}
	if (!jsonData["installmentTime"].isNull()) 
	{
		this->m_installmentTm = jsonData["installmentTime"].asInt();
	}
	CUtils::getJsonStringField(jsonData, "installmentBank", m_installmentBank);
	if (!jsonData["koukuanCard"].isNull()) 
	{
		this->m_cutPaymentCard = jsonData["koukuanCard"].asInt();
	}
}

void ConsumerCarModel::toJson(Json::Value& jsonData)
{
	if (this->m_carType >= 0) 
	{
		jsonData["buyCarType"] = this->m_carType;
	}
	if (this->m_carBrand >= 0) 
	{
		jsonData["carBrand"] = this->m_carBrand;
	}
	if (this->m_buyTime >= 0) 
	{
		 jsonData["buyTime"] = this->m_buyTime;
	}
	if (this->m_buyPrice.GetLength() > 0) 
	{
		 jsonData["buyPrice"] = this->m_buyPrice.GetBuffer();
	}
	if (this->m_appraisement.GetLength() > 0) 
	{
		 jsonData["appraisePrice"] = this->m_appraisement.GetBuffer();
	}
	if (this->m_propertyRight >= 0) 
	{
		 jsonData["propertyRight"] = this->m_propertyRight;
	}
	if (this->m_installmentTm >= 0) 
	{
		jsonData["installmentTime"] = this->m_installmentTm;
	}
	if (this->m_installmentSum.GetLength() > 0) 
	{
		 jsonData["loanMoney"] = this->m_installmentSum.GetBuffer();
	}
	if (this->m_installmentBank >= 0) 
	{
		 jsonData["installmentBank"] = this->m_installmentBank.GetBuffer();
	}
	if (this->m_monthPay.GetLength() > 0) 
	{
		 jsonData["monthPay"] = this->m_monthPay.GetBuffer();
	}
	if (this->m_cutPaymentCard >= 0) 
	{
		jsonData["koukuanCard"] = this->m_cutPaymentCard;
	}
}

